package com.oocl.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import org.apache.log4j.Logger;

public class HttpConUtil {
	private static Logger logger = Logger.getLogger(HttpConUtil.class);
	
	public static void sendBanState(String address){
//		HttpURLConnection hconn = null;
//		try {
//			URL url = new URL(address);
//			URLConnection conn = url.openConnection();
//			hconn = (HttpURLConnection) conn;
//			hconn.setRequestMethod("GET");
//			logger.info("send ban state to Merchant server");
//		} catch (IOException e) {
//			e.printStackTrace();
//			logger.error(e);
//		} finally {
//			if (hconn != null) {
//				hconn.disconnect();
//			}
//		}
		HttpURLConnection hconn = null;
		InputStream in = null;
		String response = "";
		try {
			URL url = new URL(address);
			URLConnection conn = url.openConnection();
			hconn = (HttpURLConnection) conn;
			hconn.setRequestMethod("GET");
			in = hconn.getInputStream();
			int len = hconn.getContentLength();
			byte[] buffer = new byte[len];
			in.read(buffer);
			response = new String(buffer, "utf-8");
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (hconn != null) {
				hconn.disconnect();
			}
		}
		
		System.out.println(response);
	}

}
